<div class="layui-fluid" id="VIEW-list-table" lay-title="问卷管理">
    <div class="layui-row layui-col-space12">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body nepadmin-table-full">
                    <div class="layui-btn-container nepadmin-pad-t10 nepadmin-pad-l10">
                        <div class="layui-btn layui-btn-sm add">添加问卷</div>
                    </div>
                    <table id="list-table-question" lay-filter="list-table-question"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['admin', 'table', 'form', 'jquery'], function () {
        var $ = layui.jquery
            , layer = layui.layer
            , form = layui.form
            , admin = layui.admin
            , table = layui.table;
        var view = $('#VIEW-list-table');

        var tableFilter = 'list-table-question';
        table.render({
            elem: '[lay-filter="' + tableFilter + '"]',
            //api: 'getGoods',
            url: '/cms/question/page?token=' + admin.loginToken,
            height: 'full-165',
            cols: [[
                {title: '', type: 'checkbox', fixed: true, width: 60},
                {title: '标题', field: 'title'},
                {title: '状态', width: 120, templet: function (d) {
                        var status = {
                            2: {title: '结束', color: 'orange'},
                            1: {title: '发布中', color: 'blue'},
                            0: {title: '创建中', color: 'orange'}
                        }[d.status];
                        return '<span class="layui-badge layui-bg-' + status.color + '">' + status.title + '</span>';
                    }
                },
                {title: '操作', width: 220, align: 'center', templet: function (d) {
                        var editBtn = '<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">编辑</a>';
                        var delBtn = '<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>';
                        return editBtn + delBtn;
                    }
                }
            ]]
        });

        table.on('tool(' + tableFilter + ')', function (obj) {
            if (obj.event === 'del') {//删除行

            } else if (obj.event === "edit") {
                // 跳转新页面
                var id = obj.data.id;
                // 重新打开一个tab页
                var href = '#/question/questionEdit/id='+id;
                admin.navigate(href)
                return false
            }
        });

        view.find('.add').click(function () {
            var href = '#/question/questionEdit';
            admin.navigate(href)
            return false
        })
    })
</script>